//package java_cup;

/**
 * This class represents a part of a production which is a SymbolDraft (terminal or
 * non terminal). This simply maintains a reference to the SymbolDraft in question.
 *
 * @see java_cup.production
 * @version last updated: 11/25/95
 * @author Scott Hudson
 */
public class SymbolPart : ProductionPart {

    /*-----------------------------------------------------------*/
    /*--- Constructor(s) ----------------------------------------*/
    /*-----------------------------------------------------------*/

    /**
     * Full constructor.
     * 
     * @param symbolCount the SymbolDraft that this part is made up of.
     * @param label an optional label string for the part.
     */
    public SymbolPart(SymbolDraft symbol, String label) /*throws internal_error*/
          : base(label) {
        if (symbol == null)
            throw new InternalError("Attempt to construct a symbol_part with a null SymbolDraft");
        _symbolDraft = symbol;
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /**
     * Constructor with no label.
     * 
     * @param symbolCount the SymbolDraft that this part is made up of.
     */
    public SymbolPart(SymbolDraft symbol) /*throws internal_error*/
        : this(symbol, null) {
    }

    /*-----------------------------------------------------------*/
    /*--- (Access to) Instance Variables ------------------------*/
    /*-----------------------------------------------------------*/

    /** The SymbolDraft that this part is made up of. */
    public SymbolDraft _symbolDraft;

    /** The SymbolDraft that this part is made up of. */
    public SymbolDraft TheSymbolDraft => _symbolDraft;

    /*-----------------------------------------------------------*/
    /*--- General Methods ---------------------------------------*/
    /*-----------------------------------------------------------*/

    /** Respond that we are not an actionPart part. */
    /*@Override*/
    public override bool IsAction => false;

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Equality comparison. */
    public bool equals(SymbolPart other) {
        return other != null && base.Equals(other) && TheSymbolDraft.Equals(other.TheSymbolDraft);
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Generic equality comparison. */
    /*@Override*/
    public override bool Equals(Object? other) {
        if (!(other is SymbolPart))
            return false;
        else
            return equals((SymbolPart)other);
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Produce a hash code. */
    /*@Override*/
    public override int GetHashCode() {
        return base.GetHashCode() ^ (TheSymbolDraft == null ? 0 : TheSymbolDraft.GetHashCode());
    }

    /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */

    /** Convert to a string. */
    /*@Override*/
    public override string ToString() {
        if (TheSymbolDraft != null)
            return base.ToString() + TheSymbolDraft;
        else
            return base.ToString() + "$$MISSING-SYMBOL$$";
    }

    /*-----------------------------------------------------------*/

}
